﻿{$header}
<div id="main" class="main" >
    <div class="content">
  <h3 class="heading">编辑销售单 [ <a href="__URL__">返回列表</a> ] 
    <a class="btn btn-primary" href="__URL__/invoice/oid/{$vo.id}"> <i class="icon-shopping-cart  icon-white"></i>配货单</a>
        <a class="btn btn-primary" href="__URL__/shipping/oid/{$vo.id}"> <i class="icon-plane  icon-white"></i>快递单</a>
  </h3>
<div id="result" class="result none"></div>
<table cellpadding=3 cellspacing=3 >
    <tr><td colspan="4" class="heading h4 alert alert-info">订单号：{$vo.sale_no} 
        <span class="offset1">原单号及来源：{$vo.order_source_id|getModelName='Order_source'} | {$vo.mall_no}</span>
        
        <span class="offset1">配货状态：{$vo.prepare_status|getConfigVal="prepare_status"}</span>
        <span class="offset1">审核状态： <eq name="vo.status" value="0"> 未审核<else/> 审核通过 </eq> </span>
       </td>
</tr>
    <tr>
    
     <tr> <td>收货人：</td><td>
        <input type="hidden" name="shipping_address_id" value="{$vo.shipping_address_id}" >
        <input type="text" name="shipping_name" value="{$vo.shipping_name}"> 
    </td>
         <td>手机</td><td> <input type="text" name="mobile" value="{$vo.mobile}"> </td>
        
    </tr>
    <tr>
       <td>地址：</td><td><input type="text" class="input-xxlarge" name="address" value="{$vo.address}"> </td>
        <td>电话</td><td> <input type="text" name="phone" value="{$vo.phone}"> </td>
    </tr>

<?php 
$action_history = M('Action')->where('model ="Sale" and obj_id ='.$vo['id'] )->order('id desc')->findAll(); 
$sale_detail_ids = M('Sale_detail')->where('sale_id ='.$vo['id'])->field('id')->findAll(); //not include delete sale_detail
$detail_history = array();
$delete_sale_detail_ids = array() ;


$delete_sale_details = D('ActionHistoryView')->where('model = "Sale_detail" and field ="delete"')->field('id,diff')->findAll();
$this_del_details = array();
foreach ($delete_sale_details as $dkey => $dvalue) {
    $detail = unserialize($dvalue['diff']);
    if($detail[0]['sale_id'] == $vo['id'] ){ //得到对应的删除ACTION
       $delete_sale_detail_ids[$dkey]['id'] = $detail[0]['id']; //存入已经删除的sale_detail_id
    }
}
//the arrays contain numeric keys, the later value will not overwrite the original value, but will be appended
$sale_detail_ids = array_merge($sale_detail_ids, $delete_sale_detail_ids );
foreach ($sale_detail_ids as $k => $v) {

    $tmp_detail = M('Action')->where('model ="Sale_detail" and obj_id ='.$v['id'] )->order('id desc')->findAll();
    
    if(is_array($tmp_detail))
       $detail_history = array_merge($detail_history,$tmp_detail );
    
}

?>
<table class="table table-bordered table-striped">
    <tr><td colspan="7" class="heading h4 alert alert-info">操作日志 </td></tr>
<tr><th>序号</th><th>操作人</th><th>ip</th><th>操作时间</th><th>操作概要</th> <th>动作</th> <th>详细</th> </tr>
<volist name="action_history" id="ah"> 
    <tr>
        <td>{$ah.id}</td>
        <td>{$ah.user_id|getModelName='User'}</td>
        <td>{$ah.ip}</td>
        <td>{$ah.create_time|toDate}</td>
        <td>{$ah.comment}</td>
        <td>{$ah.action}</td>
        <?php 
        $historys = M('History')->where('action_id ='.$ah['id'])->findAll();
         ?>
        <td>
            <div class="changes" id="changeBox3" style="display: block; ">{:A('Action')->printChanges('Sale',$historys)}</div>
        </td>
    </tr>
</volist>

<volist name="detail_history" id="dh"> 
    <tr>
        <td>{$dh.id}</td>
        <td>{$dh.user_id|getModelName='User'}</td>
        <td>{$dh.ip}</td>
        <td>{$dh.create_time|toDate}</td>
        <td>{$dh.comment}</td>
        <td>{$dh.action}</td>
        <?php 
        $historys = M('History')->where('action_id ='.$dh['id'])->findAll();
         ?>
        <td>
            <div class="changes" id="changeBox3" style="display: block; ">
                <eq name="dh.action" value="删除">
                    {:dump(unserialize($historys[0]['diff']))}
                    <else/>
                    {:A('Action')->printChanges('Sale_detail',$historys)}
                </eq>
            </div>
        </td>
    </tr>
</volist>

</table>

</div>
</div>
<include file="Public:footer" />
<link rel="stylesheet" type="text/css" href="__PUBLIC__/Js/easyui/themes/default/easyui.css">
<script type="text/javascript" src="__PUBLIC__/Js/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/Js/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/Js/filter-product.js"></script>
<script type="text/javascript">
    function copy_sale_detail (id) {
        var sale_detail_id = id;
        if( sale_detail_id > 0){
        jQuery.post(
        APP+'/Sale_detail/getSaleDetail',
        {   sale_detail_id:sale_detail_id
        },
        function(data){
            data = data.data;
            $('#sale_detail').append(data.sale_detail);
        },
        'json'
        );
        }
    }
</script>
